<div id="post">
	<h2>{{guestbook.name}}</h2>
	<div id="guestbook-message" style="display: none;">{{!save_ok}}</div>
	
	<div id="guestbook-form">
		<iframe src="" name="myiframe" width="1" height="1" frameborder="0" border="0"></iframe>
		<form action="{{action}}" method="POST" enctype="multipart/form-data" target="myiframe" name="gbfrm">
		<input type="hidden" name="mode" value="write2"/>
		<input type="hidden" name="ajaj" value="1"/>
		<input type="hidden" name="is-iframe" value="1"/>
		
		<div class="field must">
			<div class="label">{{!name}}</div>
			<div class="edit"><input type="text" name="user_q_name" class="max"/></div>
			<div class="cl"></div>
			<div class="err"></div>
		</div>
		
		<div class="field must">
			<div class="label">{{!telephone}}</div>
			<div class="edit"><input type="text" name="user_q_phone" class="max"/></div>
			<div class="cl"></div>
			<div class="err"></div>
		</div>
		
		<div class="field must must-email">
			<div class="label">{{!email}}</div>
			<div class="edit"><input type="text" name="user_q_email" class="max"/></div>
			<div class="cl"></div>
			<div class="err"></div>
		</div>
		
		<div class="field must">
			<div class="label">{{!question}}</div>
			<div class="edit"><textarea name="question"></textarea></div>
			<div class="cl"></div>
			<div class="err"></div>
		</div>
		
		<div class="field">
			<div class="label">{{!avatar}}</div>
			<div class="edit"><input type="file" name="avatar"/></div>
			<div class="cl"></div>
		</div>	
		
		<div class="field captcha-field">
			<div class="label">{{!field_human}}</div>
			<div class="edit">
				<ul id="sortable">
					<li class="captchaItem">1</li>
					<li class="captchaItem">2</li>
					<li class="captchaItem">3</li>
					<li class="captchaItem">4</li>
					<li class="captchaItem">5</li>
					<li class="captchaItem">6</li>
				</ul>
			</div>
			<div class="cl"></div>
			<div class="err captchaerr"></div>
		</div>

		<div class="submit">
			<input type="submit" value="{{!btn_label}}" onclick="if (!test_captcha()) return false;return gbfrm_check();"/>
		</div>
	</form>
	</div>
</div>
<script>
function guestbook_write_ok() {
	$('#guestbook-form').css("display","none");
	$('#guestbook-message').css("display","block");
};

$.fn.shuffle = function() {
	return this.each(function(){
		var items = $(this).children();

		return (items.length)
			? $(this).html($.shuffle(items,$(this)))
		: this;
	});
}

$.fn.validate = function() {
	var res = false;
	this.each(function(){
		var arr = $(this).children();
		res =	((arr[0].innerHTML=="1")&&
			(arr[1].innerHTML=="2")&&
			(arr[2].innerHTML=="3")&&
			(arr[3].innerHTML=="4")&&
			(arr[4].innerHTML=="5")&&
			(arr[5].innerHTML=="6"));
	});
	return res;
}

$.shuffle = function(arr,obj) {
	for(
	var j, x, i = arr.length; i;
	j = parseInt(Math.random() * i),
	x = arr[--i], arr[i] = arr[j], arr[j] = x
);
	if(arr[0].innerHTML=="1") obj.html($.shuffle(arr,obj))
	else return arr;
}

$("#sortable").sortable();
$("#sortable").disableSelection();
$('#sortable').shuffle();

function test_captcha()
{
	if ($('#sortable').validate()) {
		gbfrm.mode.value="write";
		$(".captchaerr").text("");
		return true;
	}
	$(".captchaerr").text("{{!captcha_error}}");
	return false;
}

generic_site_form_init("#guestbook-form");

function gbfrm_check()
{
	var flag=generic_site_form_check("#guestbook-form");
	return flag;
}

</script>
